package com.cabrida.livestar;

import android.app.Application;
import android.content.Context;

import cn.jpush.android.api.JPushInterface;

import com.caishuij.image.core.DisplayImageOptions;
import com.caishuij.image.core.ImageLoader;
import com.caishuij.image.core.ImageLoaderConfiguration;
import com.caishuij.image.core.assist.QueueProcessingType;

public class BaseApplication extends Application {
	public static boolean isRelease = false;// TODO 发布版本时，设置为true.
	private static Application mApp;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		mApp = this;
		initImageLoader(getApplicationContext());
		JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
		JPushInterface.init(this); // 初始化 JPush
		if (isRelease) {
			BaseException.getInstance().init(mApp);
		}
	}

	public static Context getApplication() {
		return mApp;
	}
	
	public static void initImageLoader(Context context) {
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.loading_error) // 设置图片下载期间显示的图片
                .showImageForEmptyUri(R.drawable.loading_error) // 设置图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(R.drawable.loading_error) // 设置图片加载或解码过程中发生错误显示的图片
                .cacheInMemory(true).cacheOnDisk(true).build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context).defaultDisplayImageOptions(defaultOptions)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .tasksProcessingOrder(QueueProcessingType.LIFO).build();
        ImageLoader.getInstance().init(config);
    }
}